package com.ruoyi.web.controller.Dictionary;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Dictionary.domain.Zd;
import com.ruoyi.Dictionary.service.IZdService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 字典 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-08-08
 */
@Controller
@RequestMapping("/Dictionary")
public class ZdDistributionController extends BaseController
{
    private String prefix = "Dictionary/zdDistribution";
    private String prefix2 = "Dictionary/zdCoin";
	
	@Autowired
	private IZdService zdService;
	
	@RequiresPermissions("Dictionary:zd:view")
	@GetMapping("/zdDistribution")
	public String zdDistribution()
	{
	    return prefix + "/zd";
	}
	
	@RequiresPermissions("Dictionary:zd:view")
	@GetMapping("/zdCoin")
	public String zdCoin()
	{
	    return prefix2 + "/zd";
	}
	
	/**
	 * 查询字典列表
	 */
	@RequiresPermissions("Dictionary:zd:list")
	@PostMapping("/zdDistribution/list")
	@ResponseBody
	public TableDataInfo zdDistributionList(Zd zd)
	{
		zd.setType("level_chief");
		startPage();
        List<Zd> list = zdService.selectZdList(zd);
		return getDataTable(list);
	}
	
	/**
	 * 查询字典列表
	 */
	@RequiresPermissions("Dictionary:zd:list")
	@PostMapping("/zdCoin/list")
	@ResponseBody
	public TableDataInfo zdCoin(Zd zd)
	{
		zd.setType("jbxjbl");
		startPage();
        List<Zd> list = zdService.selectZdList(zd);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出字典列表
	 */
	@RequiresPermissions("Dictionary:zd:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Zd zd)
    {
    	List<Zd> list = zdService.selectZdList(zd);
        ExcelUtil<Zd> util = new ExcelUtil<Zd>(Zd.class);
        return util.exportExcel(list, "zd");
    }
	
	/**
	 * 新增字典
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存字典
	 */
	@RequiresPermissions("Dictionary:zd:add")
	@Log(title = "字典", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Zd zd)
	{		
		return toAjax(zdService.insertZd(zd));
	}

	/**
	 * 修改字典
	 */
	@GetMapping("/zdDistribution/edit/{id}")
	public String zdDistributionedit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Zd zd = zdService.selectZdById(id);
		mmap.put("zd", zd);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改字典
	 */
	@GetMapping("/zdCoin/edit/{id}")
	public String zdCoinedit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Zd zd = zdService.selectZdById(id);
		mmap.put("zd", zd);
	    return prefix2 + "/edit";
	}
	
	/**
	 * 修改保存字典
	 */
	@RequiresPermissions("Dictionary:zd:edit")
	@Log(title = "字典", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Zd zd)
	{		
		return toAjax(zdService.updateZd(zd));
	}
	
	/**
	 * 删除字典
	 */
	@RequiresPermissions("Dictionary:zd:remove")
	@Log(title = "字典", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(zdService.deleteZdByIds(ids));
	}
	
}
